<cfmodule template="../../tag/layout.cfm" bodyIsEasyUILayout="false">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
<style type="text/css">
	html,body{
        margin:0;
        width:100%;
        height:100%;
        background:#ffffff;
    }
    #map{
        width:100%;
        height:100%;
    }
</style>
<cfoutput><script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=#request.BaiduAK#"></script></cfoutput>
<div id="map"></div>
</form>
</cfmodule>
<script type="text/javascript">
	$.ajax({
	    type: "POST",
	    url: "?action=store.getall"
	}).done(function(result) {

		if(result.length == 0 ){
			$.messager.alert('提示','请先确认有门店数据！','warning');
		}else{
			if (document.createElement('canvas').getContext) {  // 判断当前浏览器是否支持绘制海量点

				var map = new BMap.Map("map", {});                        // 创建Map实例
				map.centerAndZoom(new BMap.Point(result[1].longitude, result[1].latitude), 10);     // 初始化地图,设置中心点坐标和地图级别
		   		map.enableScrollWheelZoom();                        //启用滚轮放大缩小
				var points = [];  // 添加海量点数据
				for (var i = 0; i < result.length; i++) {
		          points.push(new BMap.Point(result[i].longitude, result[i].latitude));
		        }

		        var options = {
		            size: BMAP_POINT_SIZE_BIG,
		            shape: BMAP_POINT_SHAPE_STAR,
		            color: '#d340c3'
		        }

		        var pointCollection = new BMap.PointCollection(points, options);  // 初始化PointCollection
		        pointCollection.addEventListener('click', function (e) {

		        	$.each(result, function(i, v) {
				       if(v.longitude == e.point.lng){
				       		msg = '门店名称：'+v.name+'<br/>';
				       		msg+= '门店地址：'+v.address+'<br/>';
				       		msg+= '联系电话：'+v.phone+'<br/>';
				       		if(v.linkman.trim().length>0){
				       			msg+= '联系人员：'+v.linkman+'<br/>';
				       		}
							$.messager.alert('提示',msg,'warning');
	           				return;
				       }
				    });

		        });
		        map.addOverlay(pointCollection);  // 添加Overlay
			} else {
		        alert('请在chrome、safari、IE8+以上浏览器查看本示例');
		    }
		}
	});

</script>